<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-10-3
 * Time: 下午12:56
 * To change this template use File | Settings | File Templates.
 */
class Jwawa_BaseController extends Zend_Controller_Action
{
    private $session_bag;
    protected $log;

    public function init()
    {
        $this->_helper->layout->disableLayout();
        $viewRenderer = $this->_helper->getHelper("viewRenderer");
        $viewRenderer->setNoRender(true);

        $session = new Zend_Session_Namespace();

        if (!isset($session->session_bag)){
            $session->session_bag = new Jwawa_SessionBag();
            $this->session_bag = $session->session_bag;
        }
        $this->session_bag = $session->session_bag;

        $this->log = Zend_Registry::get('log');
    }

    public function getSessionBag(){
        return $this->session_bag;
    }

    public function getJsonDataFromReq($autoTrim = true){
        $request = $this->getRequest();
        $contentType = $request->getHeader('Content-Type');
        if(strstr($contentType, 'application/json')){
           $param = Zend_Json::decode($request->getRawBody());
           if($autoTrim){
               iterTrimStr($param);
           }
           return $param;
        } else {
            return null;
        }
    }
}
